package com.leyou.item.controller;

import com.leyou.item.dto.CategoryDTO;
import com.leyou.item.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/category")
public class CategoryController {


    private  CategoryService categoryService;

    public CategoryController(CategoryService categoryService) {
        this.categoryService = categoryService;
    }

    /**
     * 根据分类id，查询商品分类
     * @param id 分类id,路径携带参数的标准接参方式
     * @return 分类对象
     */
    @GetMapping("/{id}")
    public ResponseEntity<CategoryDTO> queryCategoryById(@PathVariable("id")Long id){

        return ResponseEntity.ok(this.categoryService.queryCategoryById(id));
    }

    /**
     * 根据分类的pid查询对应的分类集合，根据父类目id，查询子类目的集合
     * get查询的标准接参方法是@RequestParam
     * @return
     */
    @GetMapping("/of/parent")
    public ResponseEntity<List<CategoryDTO>>qureyParentByPid(@RequestParam("pid")Long pid){

        return ResponseEntity.ok(this.categoryService.qureyParentByPid(pid));

    }

    /**
     *
     根据品牌id，查询商品分类的集合
     * @return
     */

    @GetMapping("/of/brand")
    public ResponseEntity<List<CategoryDTO>> queryCategoryBrandbyId(@RequestParam("id")Long id){
        return ResponseEntity.ok(this.categoryService.queryCategoryBrandbyId(id));
    }

    /**
     * 根据分类id的集合，查询商品分类的集合
     * @param ids
     * @return
     */
    @GetMapping("/list")
    public ResponseEntity<List<CategoryDTO>> listCategoryById(@RequestParam("ids")List<Long> ids){
        return ResponseEntity.ok(this.categoryService.listCategoryById(ids));
    }
}
